<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>文档</title>
  <link href="./css/semantic/semantic.min.css" rel="stylesheet">
  <link href="./css/markdown.css" rel="stylesheet">
  <style>
    body{padding-top:0;background:#f7f7f7}
    body>.ui.container{width:100%;padding:0}
    #project-title{background:#6e6e6e;width:100%;line-height:3.572rem;color:#fff;font-size:1.2rem}
    #project-title .title-wrap{font-weight:700;padding:0 12px;width:100%;max-width:1366px!important;min-width:900px;margin:0 auto}
    #project-title .left,#project-title right{display:inline-block}
    #project-title .right{float:right}
    #project-title .right .wiki-actions .menu{left:auto;right:0;margin-top:.4em!important}
    #wiki-preview-container{width:100%;max-width:1366px!important;min-width:900px;padding:0;border:1px solid #e3e9ed;border-top:0}
    #wiki-preview>.ui.segment{margin-top:0;padding:1rem;padding-left:0;border:0}
    .hover-places{display:inline-block}
    #page-detail{width:60%;margin:0 auto}
    #page-detail .title{font-weight:700;font-size:24px;padding:12px 0;border-bottom:1px solid #ccc}
    #page-detail .content{margin-top:15px}
    .content p{word-wrap:break-word}
    #wiki-parent,#wiki-title,#wikis{display:none}
    .ui.grid{padding:0!important}
    #ex-all{cursor:pointer;color:#537c8d}
  </style>
</head>
<body>
  <div class="ui container">
    <div id="project-title">
      <div class="title-wrap">
        <div class="left">
          <i class="icon eye"></i>
          文档预览:
          小鹿直播接口文档
        </div>
        <div class="right">
          Export by Gitee
        </div>
      </div>
    </div>

    <div class="ui container" id="wiki-preview-container">
      <div id="wiki-preview">
        <div class="ui segment">
          <div id="page-detail" class="markdown-body">
            <div class='title'>接口访问规范</div><div class='content'><p>接口地址: <a target="_blank" href="http://admin.xiaolutv.com/Api">http://admin.xiaolutv.com/Api</a>;</p>

<p>api_key： 1fc3d41307e8de3ac0da9e2f032d7b5b;</p>

<p>客户端接口传输规则:</p>
<div class="white"><div class="highlight"><pre>1.用method参数(base64)来动态调用不同的接口,接口地址统一为 http://admin.xiaolutv.com/Api
2.将要传过来的参数组成一个数组，数组添加timestamp元素(当前时间戳,精确到秒)，将数组的键值按照自然排序从大到小排序
3.将数组组成 key=val&amp;key=val的形式的字符串，将字符串与api_key连接在一起,用md5加密一次(32位小写),得到sign
4.将sign添加到参数数组中
5.将参数数组转换成json用post请求请求接口地址,key值为param
</pre></div></div>
<p>php 示例代码</p>
<div class="white"><div class="highlight"><pre>    //生成签名
   private  function  create_sign($data){
    $api_key = "1fc3d41307e8de3ac0da9e2f032d7b5b";
    krsort($data);//将参数数组key值按照自然排序从大到小排序
    $sb = '';
    foreach($data as $key=&gt;$val){ //将排序后的参数数组按照key=val&amp;key=val的形式组成字符串，将字符串与api_key连接，用md5加密一次(32位小写)，得到sign
        $sb .= $key . '=' . $val . '&amp;';
    }
    $sb .= $api_key;
    $sign = md5($sb);
    return $sign;
}
</pre></div></div>
<p>//客户端微信授权登陆后调用接口示例</p>

<p>public function test(){</p>
<div class="white"><div class="highlight"><pre>    $openid='o7gRa0o9hhWa1eoH';
    $api_url='http://admin.xiaolutv.com/Api';
    $data['openid']=$openid;
    $data['nickname']='╮(╯▽╰)╭';
    $data['sex']=1;
    $data['province']='湖南';
    $data['city']='长沙';
    $data['headimgurl']='http://wx.qlogo.cn/mmopen/XiaeJeoCQ1EIo7G0Q7A1ggvIy9cG49I51ZBUKjvInatSEYP6gH9QvaO20g1w6TQJc61N7cSdjibo6uyelxwzLLxG6Mhiaic2Nf8v/0';
    $data['method']=base64_encode('addWxUser');
    $data['timestamp']=time();
    $sign=$this-&gt;create_sign($data);
    $data['sign']=$sign;
    $arr['param']=json_encode($data);
    $result=curlPost($api_url,$arr);
</pre></div></div>
<p>}</p>

<p>上面参数最后生成的json<br>
$arr['param']='{"openid":"o7gRa0o9hhWa1eoH","nickname":"\u256e(\u256f\u25bd\u2570)\u256d","sex":1,"province":"\u6e56\u5357","city":"\u957f\u6c99","headimgurl":"http:\/\/wx.qlogo.cn\/mmopen\/XiaeJeoCQ1EIo7G0Q7A1ggvIy9cG49I51ZBUKjvInatSEYP6gH9QvaO20g1w6TQJc61N7cSdjibo6uyelxwzLLxG6Mhiaic2Nf8v\/0","method":"YWRkV3hVc2Vy","timestamp":1507531278,"sign":"2d7f44580f138fda081c1d6dc00fdd2a"}';</p>
</div><div class='title'>注册用户</div><div class='content'><p>方法名称<br>
addWxUser</p>

<p>参数 </p>

<p>openid      微信openid </p>

<p>nickname    微信昵称</p>

<p>sex         性别 </p>

<p>province    省份</p>

<p>city        城市</p>

<p>headimgurl  头像 </p>

<p>method      方法名称  </p>

<p>timestamp   时间戳</p>

<p>sign        签名 </p>
</div>
          </div>
        </div>
      </div>
      </div>
  </div>
</body>
</html>